﻿using System;
using SmartHRMS.Model.Account;
using SmartHRMS.Infrastructure;

namespace SmartHRMS.NhibernateRepository
{
    public class PrincipalRepository : BaseRepository<Principal>, IPrincipalRepository
    {
        #region ICustomPrincipalRepository Members

        public User LoadUserById(Guid userId)
        {
            throw new NotImplementedException();
        }

        public User LoadUserByUserName(string userName)
        {
           return SessionFactory.GetCurrentSession().CreateQuery("select o from User o where UserName='" + userName + "'").UniqueResult<User>();
        }

        public User ValidateLogin(string userName, string password)
        {
            return SessionFactory.GetCurrentSession().CreateQuery("select o from User o where UserName='" + userName + "' and Password='" + password + "'").UniqueResult<User>();
        }

        #endregion

        #region ICustomPrincipalRepository Members

        public User User
        {
            get { throw new NotImplementedException(); }
        }

        public void Logout(Guid userId)
        {
            throw new NotImplementedException();
        }

        public void Act()
        {
            throw new NotImplementedException();
        }

        public LoginResults Login(string userName, string password)
        {
           User user= SessionFactory.GetCurrentSession().CreateQuery("select o from User o where UserName='" + userName + "' and Password='" + password + "'").UniqueResult<User>();
            if(user !=null){
                return LoginResults.Successful;
            }
           return LoginResults.InvalidCredential;
        }

        #endregion
    }
}
